package com.alks.function.controller.procurement;

import com.alks.common.aop.ApiRestController;
import com.alks.common.aop.RoleCheck;
import com.alks.common.aop.WebLogger;
import com.alks.entity.data.response.ResponseInfo;
import com.alks.function.data.request.procurement.ReviewMaterialRequest;
import com.alks.function.service.procurement.ReviewMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@ApiRestController("/ReviewMaterial")
@Slf4j
@Api(tags = {"采购部-评审资料建档"})
@RoleCheck(prgIds = {"140102","150104"})
public class ReviewMaterialController {

    @Autowired
    private ReviewMaterialService reviewMaterialService;

    @WebLogger
    @PostMapping("/getReviewMaterialList")
    @ApiOperation(value = "评审资料查询",tags = "采购部-评审资料建档")
    public ResponseInfo getReviewMaterialList(@RequestBody ReviewMaterialRequest request){
        return reviewMaterialService.getReviewMaterialList(request);
    }
    //查询的时候也将排序参数传进去，默认为传排序字段0+lotNo(lotNo倒序)
    //在前端设置双击的列为传的排序字段，然后将其值改为1，然后再次点击，将其值改为0，这样就实现了排序

    @WebLogger
    @PostMapping("/reviewMaterialUpdate")
    @ApiOperation(value = "更新指令",tags = "采购部-评审资料建档")
    public ResponseInfo reviewMaterialUpdate(@RequestBody List<ReviewMaterialRequest> request){
        return reviewMaterialService.reviewMaterialUpdate(request);
    }

    @WebLogger
    @GetMapping("/reviewMaterialAdd")
    @ApiOperation(value = "更新指令（按钮）",tags = "采购部-评审资料建档")
    public ResponseInfo reviewMaterialAdd(){
        return reviewMaterialService.reviewMaterialAdd();
    }

    @WebLogger
    @PostMapping("/selectAndCopy")
    @ApiOperation(value = "勾选复制",tags = "采购部-评审资料建档")
        public ResponseInfo selectAndCopy(@RequestParam List<String> lotNos, @RequestParam String lotNo){
        return reviewMaterialService.selectAndCopy(lotNos,lotNo);
    }

    @WebLogger
    @PostMapping("/addReviewMaterial")
    @ApiOperation(value = "评审资料增加",tags = "采购部-评审资料建档")
    public ResponseInfo addReviewMaterial(@RequestBody ReviewMaterialRequest request){
        return reviewMaterialService.addReviewMaterial(request);
    }

    @WebLogger
    @PostMapping("/deleteReviewMaterial")
    @ApiOperation(value = "评审资料删除",tags = "采购部-评审资料建档")
    public ResponseInfo deleteReviewMaterial(@RequestBody ReviewMaterialRequest request){
        return reviewMaterialService.deleteReviewMaterial(request);
    }

    @WebLogger
    @PostMapping("/exportReviewMaterial")
    @ApiOperation(value = "导出",tags = "采购部-评审资料建档")
    public void exportReviewMaterial(@RequestBody List<String> lotNoList, HttpServletResponse response) throws IOException {
        reviewMaterialService.exportReviewMaterial(lotNoList,response);
    }
}
